package com.ygu.user.service.adapter;

import com.ygu.websocket.domain.entity.User;
import com.ygu.websocket.domain.enums.WSBaseResp;
import com.ygu.websocket.domain.enums.WSRespTypeEnum;
import com.ygu.websocket.domain.ws.WSLoginSuccess;
import com.ygu.websocket.domain.ws.WSLoginUrl;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;


/**
 * 微信的类型转换
 */
public class WSAdapter {
    public static WSBaseResp<?> builderLoginResp(WxMpQrCodeTicket wxMpQrCodeTicket) {
        WSBaseResp<WSLoginUrl> wsBaseResp = new WSBaseResp<>();
        WSLoginUrl wsLoginUrl = WSLoginUrl.builder().loginUrl(wxMpQrCodeTicket.getUrl()).build();
        wsBaseResp.setData(wsLoginUrl);
        wsBaseResp.setType(WSRespTypeEnum.LOGIN_URL.getType());
        return wsBaseResp;
    }

    public static WSBaseResp<?> buildResp(User user, String token) {
        WSBaseResp<WSLoginSuccess> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.LOGIN_SUCCESS.getType());
        WSLoginSuccess build = WSLoginSuccess.builder().avatar(user.getAvatar()).name(user.getName())
                .token(token).uid(user.getId()).build();
        resp.setData(build);
        return resp;
    }

    public static WSBaseResp<?> buildAuthorizeResp() {
        WSBaseResp<WSLoginSuccess> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.LOGIN_SCAN_SUCCESS.getType());
        return resp;
    }
}
